<?php
session_start();
if(!isset($_SESSION['id'])){
    header('Location: login.php');
    exit;
}
include_once("../controller/sala_controller_class.php");
include_once("../controller/campus_controller_class.php");

$objPredio = new PredioController();
$listPredio = $objPredio->selecionar();
      
?>
<!DOCTYPE html>
<html lang="en" class="no-js">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        <title>::: SOS UNITAU -- Sistema de ordem de serviço</title>

        <link rel="shortcut icon" href="img/logo.jpg">
        <link rel="stylesheet" type="text/css" href="css/normalize.css" />
        <link rel="stylesheet" type="text/css" href="css/demo.css" />
        <link rel="stylesheet" type="text/css" href="css/icons.css" />
        <link rel="stylesheet" type="text/css" href="css/style2.css" />
        <link rel="stylesheet" type="text/css" href="css/StylePage.css" />
        <link rel="stylesheet" type="text/css" href="css/default.css" />
        <link rel="stylesheet" type="text/css" href="css/component.css" />
        <script type="text/javascript" src="js/jquery1.6.min.js"></script>
        <script src="js/jquery.maskedinput-1.3.min.js"></script>

<!--        <script type="text/javascript"> PARA NAO CONFLITAR 

            var $JQuery = jQuery.noConflict();
        </script>-->

        <script>
        $(document).ready(function () {
            $('#novaSala').click(function () {

                var ident = $('#txtSala').val().trim();
                var andar = $('#txtAndar').val().trim();
                var predio = $('#txtPredio').val().trim();

                if (ident == "") {
                    alert('Preencha a identificação');
                } else if (andar == "") {
                    alert('Preencha o andar');
                } else if (predio == 0) {
                    alert('Preencha o predio');
                } else {
                    
                    $.post("../funcoes/nova_sala.php", {ident: ident, andar: andar, predio: predio}, function (retorno) {

                        alert("Sala cadastrada com sucesso!");
                        location.reload();
                    }, "json").fail(function () {
                        alert("erro");
                    });
                }
            });
        });
    </script>
    
        <script>
            $(document).ready(function(){
                
                $('#txtPredio').change(function(){
                    
                    var id = $('#txtPredio').val();
                    
                    $.post("../funcoes/campusPorPredio.php",{id: id},function(data){
                        $('#txtCampus').val(data);
                    });
                });
            });
        </script>

    </head>
    <body style="overflow-x: hidden">
        <div class="loading"></div>
        <div class="container"> <!-- container -->



            <!-----------------------------CONTEUDO DA PÁGINA --------------------------------->
            
            
            <!------- SEGUE ABAIXO ------->



            <div class="barra-superior"></div>
            <div class="sobre-empresa">
                Powered by: Grupo NOP
            </div>

            
            
            <!------------- CONTEUDO DE FORMULARIOS---------------------->

            <div class="titulo-page">
                ::: Manipular Salas
            </div>
        <form name="adicionarCEP" id="adicionarCEP" method="post" enctype="multipart/form-data" action="" class="style-form">

            <fieldset style="width:30px;">
                <legend>Nova Sala: </legend>
                <table width="800px" class="table-form">
                    <tr><!-- ALTERADO -->
                        <td> <label for="txtCampus"> Campus: </label> </td>
                        <td> <input name="txtCampus" id="txtCampus" readonly />
                    </tr>
                    <tr><!-- ALTERADO -->
                        <td> <label for="txtPredio"> Prédio: </label> </td>
                        <td> <select name="txtPredio" id="txtPredio"> 
                                <option value="0">Selecione</option>
                                <?php foreach ($listPredio as $predio) { ?>
                                    <option value="<?= $predio->getId() ?>"><?= $predio->getNome() ?></option>
                                <?php } ?>
                            </select></td>
                    </tr><!-- ALTERADO -->
                    <tr>
                        <td> <label for="txtSala"> Identificação da Sala: </label> </td>
                        <td> <input name="txtSala" id="txtSala" type="text"  required placeholder="Ex: ID-09090"/></td>
                    <tr/>
                    <tr>
                        <td> <label for="txtAndar"> Andar: </label> </td>
                        <td> <input name="txtAndar" id="txtAndar" type="text" required placeholder="Ex: 5º andar" /></td>
                    </tr>



                </table>
                <input type="button" value="Gravar" id="novaSala" class="botao"  style="display:inline-block; margin-left:50%; margin-top:3%;" />
                <input type="button" value="Cancelar" style="margin-left:5%;" onClick="javascript:c = window.confirm('Deseja Realmente cancelar?');
                        if (c == true) {
                            self.close();
                        } else {
                        }" class="botao" />    
            </fieldset>

        </form>
            
              <?php include_once("menuLateral.php"); ?>
         </div><!-- FECHA CONTAINER -->
        
         
         <div class="barra-superior" style="margin-top:193px; height:80px; margin-left:80px"></div>
         
    </body>
    
    
<script src="js/classie.js"></script>
<script src="js/borderMenu.js"></script>
</html>
